package com.gitee.slowcreator.http.file.download.hutool;

import cn.hutool.core.io.FastByteArrayOutputStream;
import cn.hutool.core.io.StreamProgress;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.gitee.slowcreator.http.file.download.template.AbstractByteFileDownload;

/**
 * @author zxw
 * @date 2023/6/11 15:08
 */
public class HutoolByteFileDownload extends AbstractByteFileDownload<HttpRequest, HttpResponse> {

    @Override
    protected byte[] getByteData(HttpRequest request, HttpResponse response) {

        FastByteArrayOutputStream os = new FastByteArrayOutputStream();
        // 写入数据到 输出流 这个流关不关无所谓 反正都是空实现
        response.writeBody(os, true, new StreamProgress() {
            @Override
            public void start() {

            }

            @Override
            public void progress(long total, long progressSize) {

            }

            @Override
            public void finish() {

            }
        });
        return os.toByteArray();
    }

    @Override
    protected String getContentDisposition(HttpRequest request, HttpResponse httpResponse) {
        return null;
    }

    @Override
    protected String getRequestUrl(HttpRequest request, HttpResponse httpResponse) {
        return request.getUrl();
    }
}
